package jmodel;

import java.security.Principal;
import java.util.Calendar;

import jf.jextn.JExtn;
import jf.jextn.util.Localization;
import jf.jextn.xml.Xmlizable;

public abstract class MetadataSupport implements Xmlizable, Comparable<MetadataSupport> {
    private static final long serialVersionUID = 1L;

    protected final String name;

    private String description;

    private String longDescription;

    private Calendar created;

    private Calendar modified;

    private Principal createdBy;

    private Principal updatedBy;

    private int sortOrder;

    protected MetadataSupport(String name) {
        JExtn.checkNull(name, "name is required");

        this.name = name;
        this.created = Localization.getNow();
    }

    protected MetadataSupport(String name, Principal creater) {
        this(name);

        this.createdBy = creater;
    }

    public String getName() {
        return name;
    }

    public Calendar getCreated() {
        return created;
    }

    public void setCreated(Calendar created) {
        this.created = created;
    }

    public Calendar getModified() {
        return modified;
    }

    public void setModified(Calendar modified) {
        this.modified = modified;
    }

    public Principal getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(Principal createdBy) {
        this.createdBy = createdBy;
    }

    public Principal getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(Principal updatedBy) {
        this.updatedBy = updatedBy;
    }

    public String getLongDescription() {
        return longDescription;
    }

    public void setLongDescription(String longDescription) {
        this.longDescription = longDescription;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public int compareTo(MetadataSupport o) {
        return sortOrder - o.sortOrder;
    }

    public int getSortOrder() {
        return sortOrder;
    }

    public void setSortOrder(int sortOrder) {
        this.sortOrder = sortOrder;
    }

    @Override
    public abstract boolean equals(Object obj);

    @Override
    public abstract int hashCode();

}
